package mylib.archive.y2012.m09.IFMO_Train;

import mylib.dir.FastInputReader;

import java.io.PrintWriter;
import java.math.BigInteger;

public class TaskE {
    public void solve(int testNumber, FastInputReader in, PrintWriter out) {
//        for (int n = 1; n <= 10000; ++n) {
//            int d1 = smart(n, 1000000);
//            int d2 = (int) brute(n, 1000000);
//            if (d1 != d2) {
//                int deb = 1;
//            }
//        }
        long n = in.nextLong();
        int mod = in.nextInt();
        out.print(smart(n, mod));
    }

    int smart(long n, int mod) {
        long s = 0;
        long d;
        for (d = 1; d * d <= n; ++d)
            s = (s + n / d * d) % mod;
        for (long val = n / (d - 1) - 1; val >= 1; --val) {
            long l = n / (val + 1) + 1;
            long r = n / val;
            s += getsum(l, r, mod) * val % mod;
            s %= mod;
        }
        return (int) (s % mod);
    }

    private int getsum(long l, long r, int mod) {
        return BigInteger.valueOf(l + r).multiply(BigInteger.valueOf(r - l + 1)).shiftRight(1).mod(BigInteger.valueOf(mod)).intValue();
    }

    long get(long n) {
        long s = 0;
        for (long d = 1; d * d <= n; ++d) {
            if (n % d == 0) {
                s += d;
                if (n / d != d)
                    s += n / d;
            }
        }
        return s;
    }

    long brute(long n, int mod) {
        long s = 0;
        for (int i = 1; i <= n; ++i) {
            s = (s + get(i)) % mod;
        }
        return s;
    }
}
